package com.ttg.web.redis;

import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

/**
 * @author ZQ
 * @version 1.0
 * @Description
 * @date 2021/3/15 18:23
 */
public class RedisConstants {
    public static final String RRDISLOCK = "redis-lock";
    public static final String SENTRY = "sentry";
    public static final String IMMED_QRCODE = "immed_qrcode";
    public static final String MASTER_SLAVE = "masterSlave";
    public static final String STAND_ALONE = "standAlone";
    public static final String BILL_RECONCILIATION_LOCK = "bill_reconciliation_lock_";

    /**
     * 运营平台登录缓存code
     */
    public static final String ORGAN_USER_LOGIN_CODE = "organ:user:login_code_";
    public static final String ORGAN_USER_MOBILE_CODE = "organ:user:mobile_code_";
    public static final String ORGAN_USER_EMAIL_CODE = "organ:user:email_code_";
    /**
     * 总控登录code
     */
    public static final String MANAGE_USER_LOGIN_CODE = "manage:user:login_code_";
    public static final String MANAGE_USER_LOGIN_T_CODE = "manage:user:login_token_";
    public static final String MANAGE_USER_LOGIN_INFO = "manage:user:login_info_";


    /**
     * 商户云code
     */
    public static final String MERCHANT_USER_LOGIN_CODE = "merchant:user:login_code_";
    public static final String MERCHANT_USER_PASSWORD_FORGET_CODE = "merchant:user:password_forget_code";

    /**
     * 优惠券客户端登录缓存code
     */
    public static final String COUPON_CLIENT_USER_MOBILE_CODE = "coupon_client:user:mobile_code_";
    /**
     * 优惠券客户端活动验证code
     */
    public static final String COUPON_CLIENT_ACT_CODE = "coupon_client:act:code_";
    /**
     * 优惠券自定义延时消息
     */
    public static final String COUPON_CLIENT_DELAYED_CODE = "coupon_client:delayed:code_";
    /**
     * 优惠券活动
     */
    private static final String COUPON_ACTIVITY_PREFIX = "coupon_activity:";
    private static final String COUPON_ACTIVITY_ID = COUPON_ACTIVITY_PREFIX + "caiId:%s:";
    private static final String COUPON_ACTIVITY_ID_COUPON = COUPON_ACTIVITY_ID + "coupon";
    private static final String COUPON_ACTIVITY_ID_DETAIL = COUPON_ACTIVITY_ID + "detail";
    private static final String COUPON_ACTIVITY_CLIENT_INDEX = COUPON_ACTIVITY_ID + "client:team_no:%s:detail";
    private static final String COUPON_ACTIVITY_CITY_CHECK = COUPON_ACTIVITY_ID + "cityId_join_flag:%s";
    private static final String COUPON_ACTIVITY_KEY2ID = COUPON_ACTIVITY_PREFIX + "key:%s";

    /**
     * 一次发放数量
     */
    private static final String COUPON_ACTIVITY_ID_CAC_BUY_LIMIT = COUPON_ACTIVITY_ID + "cacId:%s:buy_limit";
    /**
     * 总数
     */
    private static final String COUPON_ACTIVITY_ID_CAC_NUM = COUPON_ACTIVITY_ID + "cacId:%s:cup_num";
    private static final String COUPON_ACTIVITY_ID_USER_JOIN_MAX_NUM = COUPON_ACTIVITY_ID + "user_join_max_num";
    private static final String COUPON_ACTIVITY_ID_JOIN_MAX_NUM = COUPON_ACTIVITY_ID + "user_max_num";

    private static final String SECKILL_QUEUE_PREFIX = "seckill:queue:";
    private static final String CAI_WAITING_RDQUEUE = SECKILL_QUEUE_PREFIX + "cai_id:%s:wait";
    private static final String CAI_USER_STATUS_QUEUE = SECKILL_QUEUE_PREFIX + "cai_key:%s:cac_id:%s:vip_id:%s";

    public static String getCupActCupKey(Long caiId) {
        Objects.requireNonNull(caiId);
        return String.format(COUPON_ACTIVITY_ID_COUPON, caiId);
    }

    /**
     * 活动详情
     *
     * @param caiId 活动编号
     * @return
     */
    public static String getCupActDetailKey(Long caiId) {
        Objects.requireNonNull(caiId);
        return String.format(COUPON_ACTIVITY_ID_DETAIL, caiId);
    }

    public static String getCupActClientDetailKey(Long caiId, String teamNo) {
        Objects.requireNonNull(caiId);
        return String.format(COUPON_ACTIVITY_CLIENT_INDEX, caiId, teamNo);
    }

    public static String getCupActCityCheckKey(Long caiId, String cityId) {
        Objects.requireNonNull(caiId);
        if (StringUtils.isBlank(cityId)) {
            throw new IllegalArgumentException();
        }
        return String.format(COUPON_ACTIVITY_CITY_CHECK, caiId, cityId);
    }

    public static String getCupActKey2IdKey(String key) {
        if (StringUtils.isBlank(key)) {
            throw new IllegalArgumentException();
        }
        return String.format(COUPON_ACTIVITY_KEY2ID, key);
    }

    public static String getUpdateCupActKey(Long caiId) {
        Objects.requireNonNull(caiId);
        return String.format(COUPON_ACTIVITY_ID, caiId);
    }

    public static String getCupActCacCupNumKey(Long caiId, Long cacId) {
        Objects.requireNonNull(caiId);
        Objects.requireNonNull(cacId);
        return String.format(COUPON_ACTIVITY_ID_CAC_NUM, caiId, cacId);
    }

    public static String getCupActCacBuyLimitKey(Long caiId, Long cacId) {
        Objects.requireNonNull(caiId);
        Objects.requireNonNull(cacId);
        return String.format(COUPON_ACTIVITY_ID_CAC_BUY_LIMIT, caiId, cacId);
    }

    public static String getCupActUserJoinMaxNumKey(Long caiId) {
        Objects.requireNonNull(caiId);
        return String.format(COUPON_ACTIVITY_ID_USER_JOIN_MAX_NUM, caiId);
    }

    public static String getCupActJoinMaxNumKey(Long caiId) {
        Objects.requireNonNull(caiId);
        return String.format(COUPON_ACTIVITY_ID_JOIN_MAX_NUM, caiId);
    }

    public static String getCaiWaitSeckillRDQueueKey(Long caiId) {
        Objects.requireNonNull(caiId);
        return String.format(CAI_WAITING_RDQUEUE, caiId);
    }

    public static String getCaiSeckillUserStatusQueueKey(String caiKey, Long cacId, Long vipId) {
        if (StringUtils.isBlank(caiKey)) {
            throw new IllegalArgumentException();
        }
        Objects.requireNonNull(cacId);
        return String.format(CAI_USER_STATUS_QUEUE, caiKey, cacId, vipId);
    }

}
